import store from '@/store'
import router from './router'


// 白名单优化
// array.includes（xxx） 判断是否在arr里面 结果为布尔值 
const wihiList = ['/login','/reg']
router.beforeEach((to,from,next)=>{
    const token = store.state.token
    if(token){
      if(to.path === '/login' || to.path === '/reg'){
        next('/')
      }else{
        next()
      }
    }else{
      if(wihiList.includes(to.path)){
        console.log(1111);
        next()
  
      }else{
        next('/login')
      }
    }
  })